<link rel="stylesheet" type="text/css" href="__ADMIN__/h-ui/css/H-ui.min.css" />
<link rel="stylesheet" type="text/css" href="__ADMIN__/h-ui.admin/css/H-ui.admin.css" />
<link rel="stylesheet" type="text/css" href="__ADMIN__/lib/Hui-iconfont/1.0.8/iconfont.css" />
<link rel="stylesheet" type="text/css" href="__ADMIN__/h-ui.admin/skin/default/skin.css" id="skin" />
<link rel="stylesheet" type="text/css" href="__ADMIN__/h-ui.admin/css/style.css" />
<style type="text/css">
#json_data{width: 500px;height: 400px;}
.btn {background-color: #1E9FFF;display: inline-block;height: 38px;padding: 0 18px;color: #fff;font-size: 14px;border: none;border-radius: 2px;cursor: pointer;margin: 20px;float: right;}
</style>
<article class="cl pd-20">
	<form onsubmit="return false" class="form form-horizontal" id="form-member-add">
		<p>公众号菜单json格式数据：</p>
		<textarea id="json_data"></textarea>
		<button class="btn" onclick="send_data()">提交菜单</button>
	</form>
</article>

<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="__ADMIN__/lib/jquery/1.9.1/jquery.min.js"></script> 
<script type="text/javascript" src="__ADMIN__/lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="__ADMIN__/h-ui/js/H-ui.js"></script> 
<script type="text/javascript" src="__ADMIN__/h-ui.admin/js/H-ui.admin.page.js"></script> 
<!--/_footer /作为公共模版分离出去-->
<script type="text/javascript">
	//提交菜单json数据
	function send_data()
	{
		var json_data = $("#json_data").val();
		// 验证数据是否为json格式
		if(isJSON(json_data) === false) return layer.msg('非json格式数据');
		// 提交数据
		$.post('/admin/Weixin/createGzhMenue',{'json_data':json_data},function(res){
			var _json = JSON.parse(res);
			if(_json && _json.errcode == 0 && _json.errmsg === 'ok'){
				layer.msg('修改成功');
			}else{
				layer.msg('修改失败');
			}
		})

	}

	// 判断字符串是否为json格式
	function isJSON(str) {
	    if (typeof str == 'string') {
	        try {
	            var obj=JSON.parse(str);
	            if(typeof obj == 'object' && obj ){
	                return true;
	            }else{
	                return false;
	            }

	        } catch(e) {
	            console.log('error：'+str+'!!!'+e);
	            return false;
	        }
	    }
	    console.log('It is not a string!')
	}
</script>
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>